{% extends "manage/layout.html" %}

{% set page_title = '模块编辑 - 机构首页公告通知' %}


{% block content %}
<style>
#createnew{
    margin-left: 20px;
}
.tab{
    position: absolute;
    margin-left: 40px;
    margin-top: 10px;
}
</style>
<div class="tab">
    <div class="btn-group" role="group" aria-label="...">
        <a href="javascript:;" class="btn btn-default btn-success">内容编辑</a>
        <a href="{{ url_for('manage.inform_blocks') }}" class="btn btn-primary">模块编辑</a>
    </div>
	<a type="button" class="btn btn-default" id="createnew" href="{{ url_for('manage.create_inform') }}">新建</a>
</div>
<div class="m-content">
	<table data-toggle="table" class="table table-striped table-condensed table-bordered">
		<thead>
			<tr>
				<th data-sortable="true">ID</th>
				<th>标题</th>
				<th data-sortable="true">作者</th>
				<th data-sortable="true">最近更新</th>
				<th>管理</th>
			</tr>
		</thead>
		<tbody>
			{% for item in pagination.items %}
			<tr id="{{ item.id }}">
				<td>{{ item.id }}</td>
				<td>
                    <a href="{{ url_for('school.inform', aid=item.id) }}">{{ item.title }}</a>
				</td>
				<td>{{ item.author.name }}</td>
				<td>{{ item.updated_at }}</td>
				<td>
					<a href="{{ url_for('manage.edit_inform', aid=item.id) }}"><span class="glyphicon-edit glyphicon" title="编辑"></span></a>
					<a href="javascript:;"><span class="glyphicon glyphicon-trash" title="删除"></span></a>
				</td>
			</tr>
			{% endfor %}
		</tbody>
	</table>
	{% include "school/pagination.html" %}
</div>

<div class="modal">
	<div class="modal-dialog modal-sm">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title">确认删除</h4>
			</div>
			<div class="modal-body">
				<button class="btn btn-danger">确认</button>
				<button class="btn btn-default">取消</button>
			</div>
		</div>
	</div>
</div>
{% endblock %}
{% block js %}
<script type="text/javascript">
$(function(){
	// click trash
	var muti_delete = false;
	var inform_id;

	$('span.glyphicon-trash').bind('click',function(){
		inform_id = $(this).parents('tr').attr('id');
		$('div.modal').modal('show');
	});

	// click modal alert confirm button
	$('.modal-body button.btn-danger').bind('click',function(){
		var url = '/manage/inform/delete/' + inform_id;
		if (!muti_delete){
			if(!inform_id) return;

			$.post(url, function(data){
				if (data['code']!=0){
					alert(data['msg']);
				}
				window.location.href = "{{ url_for('manage.informs') }}";
			}, 'json');
		}

	});

	$('.modal button').bind('click',function(){
		$('.modal').modal('hide');
	});

});

</script>
{% endblock %}
